package dnl.utils.swing.clipboard;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

/**
 * 
 *
 * @author <a href="mailto:daniel.or@gmail.com">Daniel Or</a>
 *
 */
public class FileSelection implements Transferable{

	private List<File> fileList;
	private static DataFlavor[] supportedFlavors = {DataFlavor.javaFileListFlavor};
	
	public FileSelection(File f) {
		this.fileList = Collections.singletonList(f);
	}


	public FileSelection(List<File> f) {
		this.fileList = f;
	}


	@Override
	public Object getTransferData(DataFlavor flavor)
			throws UnsupportedFlavorException, IOException {
		if(!DataFlavor.javaFileListFlavor.equals(flavor)){
			throw new UnsupportedFlavorException(flavor);
		}
		return fileList;
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		return supportedFlavors;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		return DataFlavor.javaFileListFlavor.equals(flavor);
	}

}
